/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mira.org.beans;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mira.org.entidades.Agenda;

/**
 *
 * @author Nestor
 */
@Stateless
public class AgendaFacade extends AbstractFacade<Agenda> {
    @PersistenceContext(unitName = "PacienetesMiraPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public AgendaFacade() {
        super(Agenda.class);
    }
    
    public Agenda getAgendaPaciente(Integer idPaciente) {
      Agenda agenda = new Agenda();
        try {
            Query query = getEntityManager().createQuery(
                    "SELECT a FROM Agenda a, Pacientes p WHERE p.idpaciente = :idpaciente and a.idpaciente = :idpaciente");
            query.setParameter("idpaciente",idPaciente);
            query.setParameter("idpaciente", idPaciente);
            agenda = (Agenda) query.getSingleResult();

        } catch (Exception e) {
            System.out.println("error es en la consulta del facade antecedentes: "+ e);
        }
        return agenda;
    }
}
